<?php

namespace common\models\datas;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "{{%cards_send}}".
 *
 * @property integer $id
 * @property integer $site_id
 * @property integer $batch_id
 * @property integer $issuser_id
 * @property integer $reissuser_id
 * @property integer $number
 * @property integer $cardno_begin
 * @property integer $cardno_end
 * @property integer $commission_rate
 * @property integer $proportion
 * @property integer $is_withdraw
 * @property integer $created_at
 * @property integer $is_delete
 */
class CardsSend extends \common\components\bases\BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%cards_send}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['site_id', 'batch_id', 'card_send','issuser_id', 'reissuser_id', 'number', 'cardno_begin', 'cardno_end', 'commission_rate', 'proportion', 'is_withdraw', 'created_at', 'is_delete'], 'integer'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('common', '序列'),
            'site_id' => Yii::t('common', '分店id'),
            'batch_id' => Yii::t('common', '批次id'),
            'issuser_id' => Yii::t('common', '发卡人id'),
            'reissuser_id' => Yii::t('common', '接收人id(也就是二级发卡人)'),
            'number' => Yii::t('common', '发卡数量'),
            'card_send'=>Yii::t('common', '已经发卡数量'),
            'cardno_begin' => Yii::t('common', '卡开始编号'),
            'cardno_end' => Yii::t('common', '卡结束编号'),
            'commission_rate' => Yii::t('common', '佣金比例'),
            'proportion' => Yii::t('common', '分成比例'),
            'is_withdraw' => Yii::t('common', '是否为回收卡（0：默认否 1：是）'),
            'created_at' => Yii::t('common', '创建时间'),
            'is_delete' => Yii::t('common', '是否删除(0：默认未删除 1:是)'),
        ];
    }
    public function getCardsBatch()
    {
        return $this->hasOne(CardsBatch::className(), ['id' => 'batch_id']);
    }
    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
                ],
            ],
        ]);
    }
}
